package org.im.service.websocket.test;

import javax.websocket.CloseReason;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;


//@ServerEndpoint(value="/WebsocketPipeline") 
public class WebsocketPipeline extends Endpoint {
	
	private Session session;

	@Override
	public void onOpen(Session arg0, EndpointConfig arg1) {
		//一个session表示一个会话连接
		this.session = arg0;
		System.out.println("open");
		
		RemoteEndpoint.Basic remote = session.getBasicRemote();
		System.out.println("path parameters : " + session.getPathParameters());
		System.out.println("request parameters : " + session.getRequestParameterMap());
		
		session.addMessageHandler(new MyMessageHandler(remote));
	}

	@Override
	public void onError(Session session, Throwable throwable) {
		System.out.println("error");
		super.onError(session, throwable);
	}
	
	@Override
	public void onClose(Session session, CloseReason closeReason) {
		System.out.println("close");
		super.onClose(session, closeReason);
	}
	
}
